#include "robot.h"
#include"strategy.h"
#include"robotgrablodr.h"
#include "robotplayhand.h"
#include<QDebug>
Robot::Robot(QObject *parent)
    : Player{parent}
{
    m_type = Player::Robot;
}

void Robot::thinkCallLord()
{
    int weight = 0 ;
    Strategy st(this,m_cards);
    weight += st.getRangeCards(Card::Card_SJ,Card::Card_BJ).cardCount()*6;

    QVector<Cards> optSeq = st.pickOptimalSeqSingles();
    weight += optSeq.size() *5;

    QVector<Cards> bombarray = st.findCardsBycount(4);
    weight += bombarray.size()*5;

    weight += m_cards.pointcount(Card::Card_2)*3;

    Cards tmp = m_cards;
    tmp.remove(optSeq);
    tmp.remove(bombarray);
    Cards p = st.getRangeCards(Card::Card_2,Card::Card_2);
    tmp.remove(p);

    QVector<Cards> triplearray = Strategy(this,tmp).findCardsBycount(3);
    weight += triplearray.size()*4;

    tmp.remove(triplearray);

    QVector<Cards> PairArray = Strategy(this,tmp).findCardsBycount(2);
    weight +=PairArray.size()*1 ;

    if(weight >=22)
    {
        grabLordBet(3);
    }
    else if(weight <22 && weight >=18)
    {
        grabLordBet(2);
    }
    else if(weight >=10 && weight <18)
    {
        grabLordBet(1);
    }
    else
    {
        grabLordBet(0);
    }
}

void Robot::prepareCallLord()
{
    robotGrabLodr *subthread = new robotGrabLodr(this);
    connect(subthread,&robotGrabLodr::finished,this,[=](){
        qDebug()<<"叫地主机器人析构...";
        subthread->deleteLater();
    });
    subthread->start();
}

void Robot::preparePlayHand()
{
    RobotPlayHand *subThread = new RobotPlayHand(this);
    connect(subThread,&RobotPlayHand::finished,this,[=](){
        qDebug()<<" 出牌机器人析构...";
        subThread->deleteLater();
    });
    subThread->start();
}

void Robot::thingkPlayHand()
{
    Strategy st(this,m_cards);
    Cards cs = st.makeStrategy();
    playHand(cs);
}
